//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package 力扣.题库.周赛.周赛447;

public class Q2 {
    public Q2() {
    }

    public static void main(String[] args) {
        int[] nums = new int[]{2, 5, 6, 8};
        int[][] queries = new int[][]{{0, 1}, {0, 2}, {1, 3}, {2, 3}};
        boolean[] booleans = pathExistenceQueries(4, nums, 2, queries);

        for(int i = 0; i < booleans.length; ++i) {
            System.out.println(booleans[i]);
        }

    }

    public static boolean[] pathExistenceQueries(int n, int[] nums, int maxDiff, int[][] queries) {
        int queriesLength = queries.length;
        boolean[] res = new boolean[queriesLength];

        for(int i = 0; i < queriesLength; ++i) {
            if (queries[i][0] == queries[i][1]) {
                res[i] = true;
            } else {
                boolean ok = true;
                int left = queries[i][0];
                int right = queries[i][1];
                if (left > right) {
                    int temp = left;
                    left = right;
                    right = temp;
                }

                for(int j = left; j < right; ++j) {
                    if (Math.abs(nums[j] - nums[j + 1]) > maxDiff) {
                        ok = false;
                        break;
                    }
                }

                res[i] = ok;
            }
        }

        return res;
    }
}
